Environment Variables
Introduction
This document provides a detailed overview of the "Environment Variable" feature in the data menu of a Digisquares application. Environment variables are crucial for managing configuration settings that can change between different environments, such as development, staging, and production.
Definition
Environment variables are variables that store configuration settings specific to the environment in which an application is running. They allow for the separation of configuration from the application code, making it easier to manage settings that differ across environments.
Usage
- API Endpoints: Store different API endpoints for development, staging, and production.
- Database Connection Strings: Configure database connection strings specific to each environment.
- Feature Toggles: Enable or disable features based on the environment.
- Credentials: Manage environment-specific credentials securely.
Creating and Managing Environment Variables
To create and manage environment variables in a Digisquares application, follow these steps:
Step-by-Step Guide
1. Accessing the Environment Variable Menu
- Navigate to the data menu in your Digisquares application.
- Select the "Env Variable" option from the list. This will open the environment variable configuration interface.
2. Defining a New Environment Variable
- EnvName: Enter a unique name for the environment variable.
- Select Flow: Choose between "Workflow" or "PageFlow" to determine the scope of the variable.
- Stage: Select the environment stage (e.g., Development, Staging, Production).
- Name: Enter the name of the variable.
- Type: Select the data type for the variable (e.g., string, number, boolean).
- Value: Enter the initial value of the variable. Click the "+" button to add the value.
Example:
{
"envName": "APIConfig",
"flow": "Workflow",
"stage": "Development",
"variables": [
{
"name": "APIEndpoint",
"type": "string",
"value": "https://dev.api.example.com"
}
]
}
3. Saving the Environment Variable
After defining the environment name, flow, stage, name, type, and value, click the "Save" button to save the environment variable configuration. The new environment variable is now available for use throughout the application.
Example Usage
API Endpoint Configuration
To use an environment variable for API endpoint configuration:
- Define an environment variable to store the API endpoint.
- Access and update the environment variable as needed based on the environment.
{
"envName": "APIConfig",
"flow": "Workflow",
"stage": "Production",
"variables": [
{
"name": "APIEndpoint",
"type": "string",
"value": "https://api.example.com"
}
]
}
Database Connection String
To use an environment variable for database connection strings:
- Define an environment variable to store the connection string.
- Access and update the environment variable as needed based on the environment.
{
"envName": "DBConfig",
"flow": "Workflow",
"stage": "Staging",
"variables": [
{
"name": "ConnectionString",
"type": "string",
"value": "Server=staging.db.example.com;Database=MyDb;User Id=myUser;Password=myPass;"
}
]
}
Managing Existing Environment Variables
To edit or delete an existing environment variable:
- Navigate to the environment variable menu.
- Select the environment variable you wish to manage.
- Update the values, type, or name as needed, or delete the environment variable if it is no longer required.
Best Practices for Using Environment Variables
- Consistent Naming: Use consistent and descriptive names for environment variables to improve readability and maintainability.
- Security: Avoid storing sensitive information in environment variables without proper encryption or security measures.
- Centralized Management: Manage environment variables centrally to easily update and maintain settings across different environments.
- Environment Separation: Clearly separate configuration settings for different environments to prevent accidental use of incorrect settings.
Conclusion
Environment variables are a powerful feature in a Digisquares application, allowing for the management of configuration settings specific to each environment. By understanding how to define, use, and manage environment variables, you can ensure efficient configuration handling and improve the overall flexibility and security of your application.